package cn.wolfcode.wolf2w.controller;

import cn.wolfcode.wolf2w.domain.StrategyCatalog;
import cn.wolfcode.wolf2w.query.StrategyCatalogQueryObject;
import cn.wolfcode.wolf2w.service.IStrategyCatalogService;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/strategyCatalog")
public class StrategyCatalogController {

    @Autowired
    private IStrategyCatalogService strategyCatalogService;

    //列表显示
    @RequestMapping("/list")
    public String list(Model model, StrategyCatalogQueryObject qo){
        Page<StrategyCatalog> page = strategyCatalogService.query(qo);
        model.addAttribute("page", page);
        model.addAttribute("qo", qo);
        return "/strategyCatalog/list";
    }

    //添加数据
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(StrategyCatalog strategyCatalog){
        strategyCatalogService.saveOrUpdate(strategyCatalog);
        return JsonResult.success();
    }

    //关联目的地
    @RequestMapping("/listDests")
    @ResponseBody
    public Object listDests() {
        List<StrategyCatalog> strategyCatalogs = strategyCatalogService.selectAll();
        System.out.println(strategyCatalogs);
        return strategyCatalogs;

    }

    //删除
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(String id){
        strategyCatalogService.delete(id);
        return JsonResult.success();
    }




}
